﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Collections;

namespace HQWeb.Progect.PhotoManage
{
    public partial class PhotoProject : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            BindDropDownList();
            if (!IsPostBack)
            {
                if (Request["id"] != null)
                {
                    hidPid.Value = Request["id"];
                    if (Request["Type"] != null)
                    {
                        if (Request["Type"] == "1")
                        {
                            BindViewURL(Request["id"].ToString());
                        }
                        else if (Request["Type"] == "2")
                        {
                            BindURL(Request["id"].ToString());
                            //Session["UPLOAD"] = "2";
                        }
                    }
                    else
                    {
                        BindURL(Request["id"].ToString());
                    }
                }
                if (Session["FILE_ID"] != null)
                {
                    hidOtherPid.Value = Session["FILE_ID"].ToString();
                }

            }   
        }

        //前台设定
        protected void BindViewURL(string strID)
        {
            hidPid.Value = hidPid.Value + "-" + Session["BRANCH_ID"];
            retrun.Style["display"] = "none";
            btnclose.Style["display"] = "";
            if (Convert.ToBoolean(Session["FILE_EDIT"]) == false)
            {
                btnAdd.Style["display"] = "none";
                btnAdd.Disabled = false;
                btnClear.Style["display"] = "none";
                btnClear.Disabled = false;
                hotelselect.Style["display"] = "none";
                hotelselect.Disabled = false;
                addproject.Style["display"] = "none";
                addproject.Disabled = false;
            }
            string strJS = "getFile()";
            //string strJS = "window.returnValue= strID  + strName + strPrice ; window.close();";
            Universal.JS.RunJS(strJS);
        }

        //后台设定
        protected void BindURL(string strID)
        {
            Model.Progect.T_PUB_FILE model = new Model.Progect.T_PUB_FILE();
            BLL.Progect.T_PUB_FILE bll = new BLL.Progect.T_PUB_FILE();
            model = bll.GetModel(strID);
            Model.SysManage.T_PUB_BRANCH branchmodel = new Model.SysManage.T_PUB_BRANCH();
            BLL.SysManage.T_PUB_BRANCH branchbll = new BLL.SysManage.T_PUB_BRANCH();
            int branch_id = int.Parse(Session["BRANCH_ID"].ToString());
            branchmodel = branchbll.GetModel(branch_id);
            string ftp = "ftp://" + branchmodel.NAS_USERID + ":" + branchmodel.NAS_PASSWORD + "@" + branchmodel.NAS_IP + "/";
            //string ftp = "ftp://" + branchmodel.NAS_IP + "/";
            string url = ftp + model.URLOriginal;
            string strJS = "InitResout('" + url + "')";
            //string strJS = "window.returnValue= strID  + strName + strPrice ; window.close();";
            Universal.JS.RunJS(strJS);
        }

        #region 初始化页面下拉框
        public void BindDropDownList()
        {
            BLL.SysManage.T_PUB_DICTIONARY bll = new BLL.SysManage.T_PUB_DICTIONARY();
            List<Model.SysManage.T_PUB_DICTIONARY> il = bll.GetListArray(" FLAG = 1 order by ORDER_ID");
            BindDropData(drop_area, 1, il);
            BindDropData(drop_type, 2, il);
            BindDropData(drop_color, 4, il);
            BindDropData(drop_price, 6, il);
            BindDropData(wending_month, 7, il);
            BindDropData(dress_type, 8, il);
            BindDropData(dress_level, 9, il);
            BindDropData(dress_color, 10, il);
            BindDropData(drop_dressprice, 11, il);
            BindDropData(drop_weddingcolor, 17, il);
            BindDropData(material_star, 12, il);
            BindDropData(drop_desknum, 13, il);
            BindDropData(hotel_specification, 14, il);
            IEnumerable<Model.SysManage.T_PUB_DICTIONARY> lo = il.Where(p => p.PARENT_ID == 5);
            string x = "q";
            BindStyle(x, lo, addStyle);
            lo = il.Where(p => p.PARENT_ID == 16);
            x = "w";
            BindStyle(x, lo, addweddingstyle);
            lo = il.Where(p => p.PARENT_ID == 18);
            x = "j";
            BindStyle(x, lo, addhotelstyle);
        }
        #endregion

        #region 初始化风格
        protected void BindStyle(string y, IEnumerable<Model.SysManage.T_PUB_DICTIONARY> il, System.Web.UI.HtmlControls.HtmlTableCell controls)
        {
            StringBuilder strHtml = new StringBuilder();
            strHtml.Append("  <table width=\"90%\" ");
            int count = il.Count();
            int tempValue;
            for (int j = 0; j <= (count - 1) / 5; j++)
            {
                int i = 0;
                strHtml.Append(" <tr>");
                for (; i < 5 && 5 * j + i < count; i++)
                {
                    tempValue = 5 * j + i;
                    string strName = il.ElementAt(tempValue).NAME;
                    string strId = il.ElementAt(tempValue).ID.ToString();
                    //int temp = 5 * j + i;
                    strHtml.Append("<td align=\"left\" style=\"width:20%\">");
                    strHtml.Append(" <input type=\"checkbox\" name=\""+ y + "style\" id=\"" + y + strId + "\" value=\"" + strId + "\"/>");
                    strHtml.Append(strName);
                    strHtml.Append("</td>");
                }
                if ((5 - i) > 0)
                {
                    int sy = 5 - i;
                    strHtml.Append("<td colspan=" + sy + ">");
                    strHtml.Append("</td>");
                }
            }
            strHtml.Append(" </table>");
            controls.InnerHtml = strHtml.ToString();
        }
        #endregion

        #region 通过属性类型获取属性并绑定到下拉框
        protected void BindDropData(DropDownList drop_name, int type, List<Model.SysManage.T_PUB_DICTIONARY> il)
        {

            IEnumerable<Model.SysManage.T_PUB_DICTIONARY> lo = il.Where(p => p.PARENT_ID == type);
            drop_name.ClearSelection();
            drop_name.DataSource = lo;
            drop_name.DataTextField = "NAME"; //dropdownlist的Text的字段 
            drop_name.DataValueField = "ID";//dropdownlist的Value的字段 
            drop_name.DataBind();
            ListItem item = new ListItem("", "");
            item.Selected = true;
            drop_name.Items.Add(item);
        }
        #endregion

        #region 填充文件包含项目
        protected void getProjectData(object sender, EventArgs e)
        {
            string fileid = hidPid.Value;
            BLL.Progect.T_PUB_PROJECTFILE bll = new BLL.Progect.T_PUB_PROJECTFILE();
            DataTable modelList = bll.GetProjectList(fileid).Tables[0];
            int count = modelList.Rows.Count;
            StringBuilder strHtml = new StringBuilder();
            //StringBuilder strProjectType = new StringBuilder();
            if (count > 0)
            {
                hidProject.Value = "projectedit";
            }
            string strEID;
            string strProjectId;
            string strProjectName;
            string strPrice;
            string strBudget;
            string strType;
            string strRemark;
            for (int i = 0; i < count; i++)
            {
                strEID = modelList.Rows[i]["ID"].ToString();
                strProjectId = modelList.Rows[i]["PROJECT_ID"].ToString();
                strProjectName = modelList.Rows[i]["PROJECT_NAME"].ToString();
                strPrice = modelList.Rows[i]["PRICE"].ToString();
                strBudget = modelList.Rows[i]["BUDGET"].ToString();
                strType = modelList.Rows[i]["PROJECTTYPE_ID"].ToString();
                strRemark = modelList.Rows[i]["REMARK"].ToString();
                strHtml.Append(" <table width=\"98%\" id=\"table" + i + "\">");
                strHtml.Append(" <tr>");
                strHtml.Append(" <td align=\"right\" style=\"width:20%\">");
                strHtml.Append("服务项目名称：");
                strHtml.Append("</td>");
                strHtml.Append("<td style=\"width:20%\" align=\"left\">");
                strHtml.Append(strProjectName);
                strHtml.Append("</td>");
                strHtml.Append(" <td align=\"right\" style=\"width:20%\">");
                strHtml.Append("价 格：");
                strHtml.Append("</td>");
                strHtml.Append("<td style=\"width:20%\" align=\"left\">");
                strHtml.Append(strPrice);
                strHtml.Append("元 </td>");
                strHtml.Append("</tr>");
                strHtml.Append("<tr>");
                strHtml.Append(" <td align=\"right\" style=\"width:20%\">");
                strHtml.Append("说 明：");
                strHtml.Append("</td>");
                strHtml.Append("<td align=\"left\" colspan=\"3\">");
                strHtml.Append(strRemark);
                strHtml.Append("</td>");
                strHtml.Append("</tr>");
                strHtml.Append("<tr align=\"left\">");
                strHtml.Append("<td colspan=\"4\">");
                if (Convert.ToBoolean(Session["FILE_EDIT"]) == true)
                {
                    strHtml.Append("<input type=\"button\" id=\"del" + i + "\" value=\"删除该元素\"  onclick=\"DeleteNode('table" + i + "')\"/>");
                }
                strHtml.Append("<input type=\"text\" style=\"display: none\" value=\"" + strProjectId + "\" id=\"p" + i + "\" />");
                strHtml.Append(" <input type=\"text\" id=\"e" + i + "\" style=\"display: none\" value=\"" + strEID + "\" />");
                strHtml.Append(" <input type=\"text\" id=\"b" + i + "\" style=\"display: none\" value=\"" + strBudget + "\" />");
                strHtml.Append(" <input type=\"text\" id=\"t" + i + "\" style=\"display: none\" value=\"" + strType + "\" />");
                strHtml.Append("</td>");
                strHtml.Append(" </tr>");
                strHtml.Append(" </table>");
            }
            Addtable.InnerHtml = strHtml.ToString();
            hidCount.Value = count.ToString();
        }
        #endregion

        protected void btn_return_Click(object sender, EventArgs e)
        {
            Response.Redirect("FileList.aspx");
        }
    }
}